package it.uniroma2.sd.db;

import java.io.Serializable;
import java.util.Vector;

public interface IDB extends Serializable
{
    /**
     * Create a table with the identification name passed as parameter and insert it in the current IDB.
     * 
     * @param tablename The table identification name.
     * @return True if a new table is created, false if it already exists in this IDB.
     */
    public boolean createTable(String tablename);

    /**
     * Get the table with the identification name passed as parameter from the current IDB.
     * 
     * @param tablename The table identification name.
     * @return The requested table or null if it does not exists in this IDB.
     */
    // public ITable getTable(String tablename); // FIXME cancella ed inserisci metodi per table

    /**
     * Delete the table passed as parameter from the current IDB.
     * 
     * @param tablename The identification name for the table to delete.
     * @return True if delete complete, false otherwise.
     */
    public boolean deleteTable(String tablename);

    /* insert and update */
    /**
     * Put or update one column in the row identified by rowkey in the table identified by tablename.
     * 
     * @param tablename The key to retrieve the table.
     * @param rowkey The key corresponding to the row to be modified.
     * @param column The new column to use for put or update.
     */
    public boolean putInTable(String tablename, String rowkey, IColumn column);

    // public void put(String rowkey, String columnkey, Object columnvalue); // FIXME necessaria? vincola alla creazione di un tipo di column al suo interno

    /**
     * Put or update columns in the row identified by rowkey in the table identified by tablename.
     * <p>
     * It is also possible to pass directly an array of IColumn.
     * </p>
     * 
     * @param tablename The key to retrieve the table.
     * @param rowkey The key corresponding to the row to be modified.
     * @param columns The variable arguments list of columns to use for put or update.
     */
    public boolean putInTable(String tablename, String rowkey, IColumn... columns);

    /* get */
    /**
     * Retrieve the IColumn from the specified row in the table identified by tablename using the specified columnkey.
     * 
     * @param tablename The key to retrieve the table.
     * @param rowkey The row from which retrieve the column.
     * @param columnkey The key of the column to get.
     * @return The IColumn found or null if it does not exists in this the IColumnsGroup or the IColumnsGroup itself does not exist because the specified row is not present in this table, or the table itself does not exist in this IDB.
     */
    public IColumn getColumnFromTable(String tablename, String rowkey, String columnkey);

    /**
     * Get a whole row (that is get all the columns) from the specified table.
     * 
     * @param tablename The key to retrieve the table.
     * @param rowkey The key of the row containing the columns.
     * @return A Vector containing the columns in the specified row or null if the row is not present in this table, or the table itself is not present in this IDB.
     */
    public Vector<IColumn> getAllColumnsFromTable(String tablename, String rowkey);

    /* delete */
    /**
     * Delete a single column using its key from the specified row in the specified table.
     * 
     * @param tablename The key to retrieve the table.
     * @param rowkey The key of the row from which delete the column.
     * @param columnkey The key of the column to delete.
     * @return True if the deletion succeed, false otherwise.
     */
    public boolean deleteColumnFromTable(String tablename, String rowkey, String columnkey);

    /**
     * Delete a variable number of columns using their key from the specified row in the specified table.
     * <p>
     * If it is necessary to delete all the columns in a row use {@link #deleteRow(String)}, because it needs less effort.
     * </p>
     * 
     * @param tablename The key to retrieve the table
     * @param rowkey The key of the row from which delete the column.
     * @param columnkey The key of the column to delete.
     * @return If, after deletion, IColumnsGroup is not empty, return a positive number or zero indicating the number of non existing columns in the delete request. If, after deletion, IColumnsGroup is empty, return -(the_number_of_non_existing_column_in_the_delete_request) -2. If the row is not present in this table return -1;
     */
    public int deleteColumnsFromTable(String tablename, String rowkey, String... columnkey);

    /**
     * Delete a complete row from the specified table.
     * 
     * @param tablename The key to retrieve the table
     * @param rowkey The key of the row to delete.
     * @return True if the deletion succeed, false otherwise.
     */
    public boolean deleteRowFromTable(String tablename, String rowkey);
}
